
#include <cstdio>
#include <BPainter>

#include "HumanRole.h"

HumanRole::HumanRole(BGraphicItem* parent) : BGraphicItem(parent)
{

}
HumanRole::~HumanRole()
{

}

void HumanRole::setImage(BImage* image)
{
	_image = image;
}
const BImage* HumanRole::image() const
{
	return _image;
}
BImage* HumanRole::image()
{
	return _image;
}

void HumanRole::paint(BPainter& painter)
{
	const BRect& crect = this->centerRect();
	painter.drawImage(crect, _image);
}

void HumanRole::updateEvent(const BEvent& event)
{
	BReal time = event.time();
	if (_script)
	{
		if (_script->running())
		{
			BValue vars[2] = {0, time};
			if (!_script->call("bool update(double)", 2, vars))
			{
				const BString& message = _script->message();
				printf("Human role update failed : %s.\n", message.cstr());
			}
		}
		else
		{
			BValue vars[2] = { 0, time };
			if (!_script->call("bool start(double)", 2, vars))
			{
				const BString& message = _script->message();
				printf("Human role start failed : %s.\n", message.cstr());
			}
			if (vars[0] == false)
			{
				int a = 0;
			}
		}
	}
}
